﻿using System.Web.UI;

namespace Trentacular.Office.Server.Search.FacetedSearch
{
    /// <summary>
    /// Represents a single piece of metadata that can be used to refine a search.
    /// </summary>
    public class Facet
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="Facet"/> class.
        /// </summary>
        /// <param name="context">The faceted search context.</param>
        /// <param name="configuration">The facet provider configuration of the facet
        /// provider that generated the facet.</param>
        /// <param name="key">The facet's key.</param>
        /// <param name="displayName">The facet's display name.</param>
        /// <param name="filterString">The filter string to be appended to the where
        /// clause of the search in order to perform the refinement.</param>
        public Facet(
            FacetedSearchContext context,
            FacetProviderConfiguration configuration,
            string key,
            string displayName,
            string filterString
            )
        {
            this.FacetedSearchContext = context;
            this.Configuration = configuration;
            this.Key = key;
            this.DisplayName = displayName;
            this.FilterString = filterString;
            this.IsActive = context.IsActiveFacet(this);
        }

        /// <summary>
        /// Gets the faceted search context.
        /// </summary>
        /// <value>The faceted search context.</value>
        public FacetedSearchContext FacetedSearchContext { get; private set; }

        /// <summary>
        /// Gets the facet provider configuration of the facet provider that generated
        /// the facet.
        /// </summary>
        /// <value>The facet procider configuration of the facet provider that
        /// generated the facet.</value>
        public FacetProviderConfiguration Configuration { get; private set; }

        /// <summary>
        /// Gets the facet's key.
        /// </summary>
        /// <value>The facet's key.</value>
        public string Key { get; private set; }

        /// <summary>
        /// Gets the facet's display name.
        /// </summary>
        /// <value>The facet's display name.</value>
        public string DisplayName { get; private set; }

        /// <summary>
        /// Gets the filter string to be appended to the where clause of the search in
        /// order to perform the refinement.
        /// </summary>
        /// <value>The filter string to be appended to the where clause of the search
        /// in order to perform the refinement.</value>
        public string FilterString { get; private set; }

        /// <summary>
        /// Indicating whether this facet is actively refining the search.
        /// </summary>
        /// <value><c>true</c> if this facet is active; otherwise, <c>false</c>.
        /// </value>
        public bool IsActive { get; private set; }

        /// <summary>
        /// Gets or sets the search results count of results that apply to this facet.
        /// </summary>
        /// <value>The search results count of results that apply to this facet.
        /// </value>
        public int Count { get; set; }

        /// <summary>
        /// Gets or sets a control to be used to generate the user interface for this
        /// facet.
        /// </summary>
        /// <value>The control to be used to generate the user interface for this
        /// facet.</value>
        public Control CustomRenderer { get; set; }
    }
}
